<script>
import base from './form/index'
import $ from '@/common'
$
export default {
  extends: base,
  subModuleStore: true,
  data() {
    return {
      formDefaultData: {}
    }
  },
  computed: {},
  methods: {
    setModel(data) {
      this.setFormModel(data)
      this.fetchData()
        .then(({data}) => {
          this.dataLoad = true
          this.setData(data)
          this.actionActive()
        })
        .catch(ex => {
          console.warn(ex)
          this.actionError('ready')
          this.actionCancel()
        })
    },
    fetchData() {
      if (this.dataPath && !this.local) {
        return this.formFetch()
      } else {
        return new Promise(resolve => {
          resolve({
            data: this.rowData
          })
        })
      }
    },
    formSubmit() {
      if (!this.local) {
        return this.pushForm()
      } else {
        return new Promise((resolve) => {
          this.$owner.editRow({
            index: this.selectedIndex,
            data: this.formData
          })
          resolve()
        })
      }
    }
  },
  created() {}
}
</script>